namespace SerieSpotter.Migrations
{
    using SerieSpotter.Models;
    using System;
    using System.Collections.Generic;
    using System.Data.Entity;
    using System.Data.Entity.Migrations;
    using System.Linq;
    using System.Web.Security;
    using WebMatrix.WebData;

    public sealed class Configuration : DbMigrationsConfiguration<SerieSpotter.Models.SerieSpotterDb>
    {
        public Configuration()
        {
            this.AutomaticMigrationsEnabled = true;
            this.AutomaticMigrationDataLossAllowed = true;
        }

        protected override void Seed(SerieSpotter.Models.SerieSpotterDb context)
        {
            context.Shows.AddOrUpdate(r => r.Title,
                new Show
                {
                    Title = "Bones",
                    Year = 2005,
                    Description = "F.B.I. Agent Seeley Booth is teamed up with forensic anthropologist Dr. Temperance \"Bones\" Brennan to solve some of the most baffling and bizarre crimes ever. Booth depends on clues from the living, witnesses and suspects, while Brennan gathers evidence from the dead, relying on her uncanny ability to read clues left behind in the bones of the victims.",
                    Country = "United States",
                    Rating = 9,
                    Genre = "Crime",
                    Finished = false,
                    Seasons = new List<Season>
                    {
                        new Season
                        {   
                            Number=1, 
                            Episodes= new List<Episode>
                            {
                                new Episode{Title="Pilot", Description="Pilot episode. After returning to Washington, D.C., renowned forensic anthropologist Dr. Temperance Brennan is called in by FBI Special Agent Seeley Booth to aid an FBI investigation involving a set of bones found hidden in a lake.",
                                Date= new DateTime(2005,09,13), Network="2BE", Rating=8},
                                new Episode{Title="The man in the SUV", Description="Bones is called on to identify the body of a suspected suicide car bomber.",
                                Date= new DateTime(2005,09,20), Network="2BE", Rating=6},
                                new Episode{Title="A Boy in a Tree", Description="Bones and Booth investigate the body of a teenager found hanging in a tree on the grounds of an exclusive private school.",
                                Date= new DateTime(2005,09,27), Network="2BE", Rating=7},
                                new Episode{Title="The Man in the Bear", Description="Bones and Booth travel to Washington to investigate an arm found in a dead black bear.",
                                Date= new DateTime(2005,10,01), Network="2BE", Rating=8},
                                new Episode{Title="A Boy in a Bush", Description="When a young boy goes missing from a mall, Bones is called in to determine if it is his body found in a nearby field.",
                                Date= new DateTime(2005,10,08), Network="2BE", Rating=9}
                            },
                            PosterURL = "http://slurm.trakt.us/images/seasons/92-1.8.jpg",
                            EpisodesNumber = 22
                        },  
                        new Season{
                            Number=2, 
                            Episodes= new List<Episode>
                            {
                                new Episode{Title="The Titan on the Track", Description="An investigation into a train wreck that claimed three lives, one of them a U.S. senator.",
                                Date= new DateTime(2006,08,30), Network="2BE", Rating=6},
                                new Episode{Title="Mother and Child in the Bay", Description="Booth seeks out the husband of a missing pregnant woman after her remains wash up onshore, but the suspect disappears. ",
                                Date= new DateTime(2006,09,06), Network="2BE", Rating=7},
                                new Episode{Title="The Boy in the Shroud", Description="When a tractor-trailer collides with a garbage truck, the skeleton of a 17-year old boy is found in the trash.",
                                Date= new DateTime(2006,09,13), Network="2BE", Rating=8},
                                new Episode{Title="The Blonde in the Game", Description="Serial killer Howard Epps returns as he reaches out from prison in a deadly game involving Bones and Booth.",
                                Date= new DateTime(2006,09,20), Network="2BE", Rating=9}
                            },
                            PosterURL = "http://slurm.trakt.us/images/seasons/92-2.8.jpg",
                            EpisodesNumber = 21
                        }  
                    }
                    ,
                    PosterURL = "http://slurm.trakt.us/images/posters/92.8.jpg"
                }

                );

            context.Shows.AddOrUpdate(r => r.Title,
               new Show
               {
                   Title = "Homeland",
                   Year = 2011,
                   Description = "While in Iraq, Carrie Mathison, a Central Intelligence Agency operations officer, had been warned by an asset that an American prisoner of war had been turned by al-Qaeda.  After conducting an unauthorized operation in Iraq, Carrie is put on probation and reassigned to the CIA's Counter-terrorism Center in Langley, Virginia.",
                   Country = "United States",
                   Rating = 10,
                   Genre = "Drama",
                   Finished = false,
                   Seasons = new List<Season>
                    {
                        new Season{
                            Number=1, 
                            Episodes= new List<Episode>
                            {
                                new Episode{Title="Pilot", Description="Eight years after being listed as missing in action and presumed dead in Iraq, Marine Corps Sgt. Nicholas Brody is found alive in an Al Qaeda prison.",
                                Date= new DateTime(2011,10,02), Network="2BE", Rating=8},
                                new Episode{Title="Grace", Description="Virgil and Carrie's illegal surveillance of the Brody home is covered for a month by a dodgy court order Saul Berenson gets from 'vulnerable' judge Jeffrey Turner.",
                                Date= new DateTime(2011,10,09), Network="2BE", Rating=7},
                                new Episode{Title="Clean Skin", Description="Nicholas Brody quickly proves himself a welcome father for already doting son Chris and even brat Dana, who swallows her objections to a 'hero's perfect family' TV show despite mother's adultery for his sake.",
                                Date= new DateTime(2011,10,16), Network="2BE", Rating=8}
                            },
                            PosterURL = "http://slurm.trakt.us/images/seasons/10369-1.20.jpg",
                            EpisodesNumber = 12
                        },  
                        
                    }
                    ,
                   PosterURL = "http://slurm.trakt.us/images/posters/10369.20.jpg"

               }

               );

            context.Shows.AddOrUpdate(r => r.Title,
               new Show
               {
                   Title = "Under The Dome",
                   Year = 2013,
                   Description = "An invisible and mysterious force field descends upon a small fictional town in the United States, trapping residents inside, cut off from the rest of civilization. The trapped townsfolk must discover the secrets and purpose of the dome and its origins, while coming to learn more than they ever knew about each other.",
                   Country = "United States",
                   Rating = 6,
                   Genre = "Drama",
                   Finished = false,
                   Seasons = new List<Season>
                    {
                        new Season{
                            Number=1, 
                            Episodes= new List<Episode>
                            {
                                new Episode{Title="Pilot", Description="In Chester's Mill, Maine, a strange occurrence locks the town in under an invisible dome-like surface.",
                                Date= new DateTime(2013,06,24), Network="Vier", Rating=8},
                                new Episode{Title="The fire", Description="In a flashback, we learn that Barbie killed Julia Shumway's husband trying to collect a debt. Sheriff Howard Perkins' pacemaker exploded after he touched the dome wall.",
                                Date= new DateTime(2013,07,01), Network="Vier", Rating=7},
                                new Episode{Title="Manhunt", Description="Deputy Paul Randolph escapes from custody and Linda Esquivel sets out to find him. In the meantime, Big Jim Rennie puts together a posse together and recruits Barbie to help out.",
                                Date= new DateTime(2013,07,08), Network="Vier", Rating=8},
                                new Episode{Title="Outbreak", Description="The military units outside the dome are packing up, much to the consternation of many of the townsfolk. There is a much greater problem however when Linda falls sick, the first of many as an outbreak of meningitis spreads across the town.",
                                Date= new DateTime(2013,07,15), Network="Vier", Rating=6}
                            },
                            PosterURL = "http://slurm.trakt.us/images/seasons/19909-1.10.jpg",
                            EpisodesNumber = 13
                        },  
                        
                    }
                     ,
                   PosterURL = "http://slurm.trakt.us/images/posters/19909.10.jpg"

               }

               );



            SeedMembership();


        }

        private void SeedMembership()
        {
            var roles = (SimpleRoleProvider)Roles.Provider;
            var membership = (SimpleMembershipProvider)Membership.Provider;

            //rollen aanmaken
            if (!roles.RoleExists("Admin"))
            {
                roles.CreateRole("Admin");
            }
            if (!roles.RoleExists("User"))
            {
                roles.CreateRole("User");
            }
            if (!roles.RoleExists("Visitor"))
            {
                roles.CreateRole("Visitor");
            }

            //users aanmaken en in role toevoegen
            if (membership.GetUser("testadmin", false) == null)
            {
                membership.CreateUserAndAccount("testadmin", "admin123");
            }
            if (!roles.GetRolesForUser("testadmin").Contains("Admin"))
            {
                roles.AddUsersToRoles(new[] { "testadmin" }, new[] { "admin" });
            }

            if (membership.GetUser("testuser", false) == null)
            {
                membership.CreateUserAndAccount("testuser", "user123");
            }
            if (!roles.GetRolesForUser("testuser").Contains("User"))
            {
                roles.AddUsersToRoles(new[] { "testuser" }, new[] { "user" });
            }



        }
    }
}
